﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class GotoStatement : Statement
{
    private readonly SyntaxToken _gotoKeywordToken;


    private Identifier? _labelIdentifier;


    private IntegerLiteral? _zeroLiteral;

    internal GotoStatement(SyntaxToken gotoKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.GotoStatement, parent)
    {
        SetChildField(ref _gotoKeywordToken, gotoKeywordToken);
    }

    public SyntaxToken GotoKeywordToken => _gotoKeywordToken;

    public Identifier? LabelIdentifier => _labelIdentifier;

    public IntegerLiteral? ZeroLiteral => _zeroLiteral;

    public GotoStatement Update(Identifier labelIdentifier)
    {
        SetChildNullableField(ref _labelIdentifier, Identifier.IsDefaultOrEmpty, labelIdentifier);
        return this;
    }

    public GotoStatement Update(IntegerLiteral zeroInteger)
    {
        SetChildNullableField(ref _zeroLiteral, IntegerLiteral.IsEmptyOrDefault, zeroInteger);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, GotoKeywordToken, LabelIdentifier, ZeroLiteral);
    }
}


public static partial class NodeFactory
{
    public static GotoStatement CreateGotoStatement(SyntaxNode? parent, SyntaxToken gotoKeywordToken,
        Identifier labelIdentifier)
    {
        Debug.Assert(gotoKeywordToken.IsNode(SyntaxKinds.GotoKeywordToken));
        GotoStatement stat = new(gotoKeywordToken, parent);
        return stat.Update(labelIdentifier);
    }

    public static GotoStatement CreateGotoStatement(SyntaxNode? parent, SyntaxToken gotoKeywordToken,
        IntegerLiteral zeroInteger)
    {
        Debug.Assert(gotoKeywordToken.IsNode(SyntaxKinds.GotoKeywordToken));
        GotoStatement stat = new(gotoKeywordToken, parent);
        return stat.Update(zeroInteger);
    }
}